import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import AdminHome from '../views/AdminHome.vue'
import Wellcome from '../components/AdminComponents/wellcome.vue'
import Test2 from '../components/AdminComponents/test2.vue'
import Test3 from '../components/AdminComponents/test3.vue'
import Test4 from '../components/AdminComponents/test4.vue'
import Test5 from '../components/AdminComponents/test5.vue'
import Test6 from '../components/AdminComponents/test6.vue'
import Test7 from '../components/AdminComponents/test7.vue'
import Error from '../views/Error.vue'

// 引入加载条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.inc()
NProgress.configure({
	easing:'ease',
	speed: 800,
	showSpinner: false,
	trickleSpeed: 200,
	trickle: true,
	minimum: 0.3
})

const routes = [
	{
		path: '/',
		name: 'home',
		component: HomeView
	},
	{
		path: '/messages',
		name: 'messages',
		component: ()=>import("@/views/Messages.vue")
	},
	{
		path: '/article',
		name: 'article',
		component: ()=>import("@/views/Article.vue")
	},
	{
		path: '/test',
		name: 'test',
		component: ()=>import("@/views/test.vue")
	},
	{
		path: '/login',
		name: 'login',
		component: ()=>import("@/views/Login.vue")
	},
	{
		path: '/registe',
		name: 'registe',
		component: ()=>import("@/views/Registe.vue")
	},
	{
		path: '/mine',
		name: 'mine',
		component: ()=>import("@/views/Mine.vue")
	},
	{
		path: '/error',
		name: 'error',
		component:Error
	  },
	{
		path:'/adminhome',name:'adminhome', redirect: '/wellcome',component:AdminHome,
		children:[
			{ path:'/wellcome',name:'wellcome',component:Wellcome,meta:{title:'控制台'}},
			{ path: '/test2', name: 'test2', component: Test2, meta: {title: '测试页面2'}}, 
			{ path: '/test3', name: 'test3', component: Test3, meta: {title: '测试页面3'}},
			{ path: '/test4', name: 'test4', component: Test4, meta: {title: '测试页面4'}},
			{ path: '/test5', name: 'test5', component: Test5, meta: {title: '测试页面5'}},
			{ path: '/test6', name: 'test6', component: Test6, meta: {title: '测试页面6'}},
			{ path: '/test7', name: 'test7', component: Test7, meta: {title: '测试页面7'}},
		]
	}

	
]

const router = createRouter({
	history: createWebHistory(process.env.BASE_URL),
	routes
})

router.beforeEach((to, from, next) => {
	NProgress.start()
	//跳转错误页面
	if(to.matched.length === 0){
		next('/error')
		return
	}
	next()
})
router.afterEach((to, from) => {
	NProgress.done()
})
export default router
